/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.mycompany.psc.entities;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author A7med
 */
@Entity
@Table(name = "site_expenses_items")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "SiteExpensesItems.findAll", query = "SELECT s FROM SiteExpensesItems s"),
    @NamedQuery(name = "SiteExpensesItems.findById", query = "SELECT s FROM SiteExpensesItems s WHERE s.id = :id"),
    @NamedQuery(name = "SiteExpensesItems.findByJob", query = "SELECT s FROM SiteExpensesItems s WHERE s.job = :job"),
    @NamedQuery(name = "SiteExpensesItems.findByQuantity", query = "SELECT s FROM SiteExpensesItems s WHERE s.quantity = :quantity"),
    @NamedQuery(name = "SiteExpensesItems.findByDuration", query = "SELECT s FROM SiteExpensesItems s WHERE s.duration = :duration"),
    @NamedQuery(name = "SiteExpensesItems.findByWage", query = "SELECT s FROM SiteExpensesItems s WHERE s.wage = :wage")})
public class SiteExpensesItems implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id")
    private Integer id;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 64)
    @Column(name = "job")
    private String job;
    @Basic(optional = false)
    @NotNull
    @Column(name = "quantity")
    private int quantity;
    @Basic(optional = false)
    @NotNull
    @Column(name = "duration")
    private int duration;
    @Basic(optional = false)
    @NotNull
    @Column(name = "wage")
    private float wage;

    @Basic(optional = false)
    @NotNull
    @Lob
    @Size(min = 1, max = 65535)
    @Column(name = "notes")
    private String notes;
    @JoinColumn(name = "parent", referencedColumnName = "item_id")
    @ManyToOne(optional = false)
    private SiteExpenses parent;

    public SiteExpensesItems() {
    }

    public SiteExpensesItems(Integer id) {
        this.id = id;
    }

    public SiteExpensesItems(Integer id, String job, int quantity, int duration, float wage, String notes) {
        this.id = id;
        this.job = job;
        this.quantity = quantity;
        this.duration = duration;
        this.wage = wage;

        this.notes = notes;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getJob() {
        return job;
    }

    public void setJob(String job) {
        this.job = job;
    }

    public int getQuantity() {
        return quantity;
    }

    public void setQuantity(int quantity) {
        this.quantity = quantity;
    }

    public int getDuration() {
        return duration;
    }

    public void setDuration(int duration) {
        this.duration = duration;
    }

    public float getWage() {
        return wage;
    }

    public void setWage(float wage) {
        this.wage = wage;
    }

    public float getTotal() {
        return wage * quantity * duration;
    }

    public String getNotes() {
        return notes;
    }

    public void setNotes(String notes) {
        this.notes = notes;
    }

    public SiteExpenses getParent() {
        return parent;
    }

    public void setParent(SiteExpenses parent) {
        this.parent = parent;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof SiteExpensesItems)) {
            return false;
        }
        SiteExpensesItems other = (SiteExpensesItems) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.mycompany.psc.entities.SiteExpensesItems[ id=" + id + " ]";
    }

    public SiteExpensesItems crateCopy() {
        SiteExpensesItems copy = new SiteExpensesItems();
        copy.setDuration(duration);
        copy.setJob(job);
        copy.setNotes(notes);
        copy.setQuantity(quantity);
        copy.setWage(wage);
        return copy;

    }
}
